#ifndef OBJLOADER_H_
#define OBJLOADER_H_

#include <fstream>
#include <iostream>
#include <list>
#include <vector>

#include "ModelStructs.h"
#include "Errors.h"

struct ObjFace {
	unsigned long m_vertInd[4];
	unsigned long m_normInd[4];
	unsigned long m_size;

	ObjFace();
	ObjFace(unsigned long v1, unsigned long v2, unsigned long v3,
		unsigned long n1, unsigned long n2, unsigned long n3);
	ObjFace(unsigned long v1, unsigned long v2, 
		unsigned long v3, unsigned long v4, 
		unsigned long n1, unsigned long n2,
		unsigned long n3, unsigned long n4);
};

class ObjLoader
{
public:
	ObjLoader() {}
	~ObjLoader() {}
	int Load(const wchar_t *, std::list<Mesh*>*);
protected:
	int ReadFile(std::fstream& a_file, Mesh* o_mesh);
	void LineInterpreter(const std::string& a_line,
		std::list<Vertex>& o_vert, 
		std::list<Normal>& o_norm, 
		std::list<ObjFace>& o_face);
	int ComputeNormalInMesh(Mesh* a_mesh);
	void CreateMeshHavingNormals(
		std::list<Vertex>& a_vert, 
		std::list<Normal>& a_norm, 
		std::list<ObjFace>& a_face,
		Mesh* o_mesh);
	void CreateMeshWithOutNormals(
		std::list<Vertex>& a_vert, 
		std::list<Normal>& a_norm, 
		std::list<ObjFace>& a_face,
		Mesh* o_mesh);
private:
	void FaceInterprer(const std::string& a_line, ObjFace& o_face);

	bool m_vtP, m_vnP;
	unsigned long m_trCounter;
};


#endif //OBJLOADER_H_